#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
class Solution {
public:
    int dominantIndex(vector<int>& nums) {
       if(1==nums.size()){
            return 1;
        }
        int maxV=*max_element(nums.begin(),nums.end());
        auto it=find(nums.begin(),nums.end(),maxV);
        int index=it-nums.begin();
        nums.erase(it);
        int secondV=*max_element(nums.begin(),nums.end());
        return (secondV==0)||(maxV/secondV>=2)?index:-1;
    }

    int dominantIndex_2(vector<int>& nums) {
        int m1 = -1, m2 = -1;
        int index = -1;
        for (int i = 0; i < nums.size(); i++) {
            if (nums[i] > m1) {
                m2 = m1;
                m1 = nums[i];
                index = i;
            } else if (nums[i] > m2) {
                m2 = nums[i];
            }
        }
        return m1 >= m2 * 2 ? index : -1;
    }
};
int main()
{
   Solution s;
   vector<int> nums={3,6,1,0};
   cout<<s.dominantIndex(nums)<<endl;
   system("pause");
   return 0;
}
